﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BuyTicket.ViewModels;
using BuyTicket.Service;

namespace BuyTicket.Views
{
    /// <summary>
    /// BoardView.xaml 的交互逻辑
    /// </summary>
    public partial class BoardView : UserControl
    {
        public BoardView()
        {
            InitializeComponent();
        }

        private void BoardViewModel_Loading(object sender, SimpleMvvmToolkit.NotificationEventArgs e)
        {
            this.Dispatcher.Invoke(new Action(() =>
            {
                myError.Visibility = Visibility.Visible;
                myTool.IsEnabled = false;
            }));
            
        }

        private void BoardViewModel_Loaded(object sender, SimpleMvvmToolkit.NotificationEventArgs e)
        {
            this.Dispatcher.Invoke(new Action(() =>
            {
                myError.Visibility = Visibility.Collapsed;
                myTool.IsEnabled = true;
            }));
           
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            BoardViewModel vm = this.DataContext as BoardViewModel;
            if (vm != null)
            {
                vm.RefreshCommand.Execute(null);
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.GetNavigationService(this)
                .Navigate(new Uri("Views/ArgsView.xaml", UriKind.Relative));
        }

        private void Hyperlink_Click(object sender, RoutedEventArgs e)
        {
            BuyTicketService.Navigate("https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init");
        }
    }
}
